/*
    api:"修改职位类型"
    name:"陈小洋"
    time：2021.1.24
* */
const PostType = require('../../../control/PostType/PostType')
const tools = require('../../../tools/public');
/**
 * @api {post} /postType/updPostType 4.更新职位类型
 * @apiGroup PostType
 *
 * @apiParam {Number} level 职位层级
 * @apiParam {String} _id   职位id
 * @apiParam {String} [parentId] 父级id
 * @apiParam {String} [PostTypeName] 职位名称
 * @apiParam {String} [PostTypeDescribe] 职位描述

 *
 *
 *
 * @apiParamExample {json} Request-Example
 *{
 *
 *}
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "code": 200,
 *   "msg": "修改成功！"
 *   }
 */
module.exports = async function (req, res, next) {
    let { level,_id,parentId} = req.body;
    try {
        if (!level || !_id) return res.send(tools.ReturnData(204, '参数错误,请认真阅读接口文档！'));

        /******    处理参数为空的数据 不传给数据库    ******/
        let UpdJson = {}
        let celue = ['PostTypeName', 'PostTypeDescribe'];
        for (let i in celue) req.body[celue[i]] ? UpdJson['ChildrenList.0.'+ celue[i]] = req.body[celue[i]] : ""
        /******    👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆     ******/

        if(Number(level)===1){
            res.send(tools.ReturnData(200, '修改成功！',await PostType.Upd_ById_forLevel1(_id,UpdJson)))
        }else if(Number(level)===2){
            res.send(tools.ReturnData(200, '修改成功！',await PostType.Upd_ById_forLevel2(_id,parentId,UpdJson)))
        }else{
            res.send(tools.ReturnData(205, '其他错误！'))
        }
    } catch (e) {
        console.log(e)
        return res.send(tools.ReturnData(500, '系统内部错误！'));
    }
};